import urllib.request  # 导入 urllib.request 模块，用于发送 HTTP 请求（内置库）

# 设置目标网址（这里是 Bilibili 首页）
url = 'https://www.bilibili.com'

# 自定义请求头，伪装成正常浏览器（防止被服务器识别为爬虫）
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '
                  '(KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36 Edg/136.0.0.0'
}

# 创建一个带有请求头的 Request 对象（这样才能伪装成功）
req = urllib.request.Request(url, headers=headers)
# 下载网页(不过会被拦截)
# urllib.request.urlretrieve(url, 'bilibili.html')
# 下载图片
# urllib.request.urlretrieve('https://www.bing.com/images/search?view=detailV2&ccid=KGugGauI&id=841AF31AF075F7407B09F6516C9CE09F796628AF&thid=OIP.KGugGauIyoWp8BUaseXo_wHaE4&mediaurl=https%3a%2f%2fpic2.zhimg.com%2fv2-c2e79191533fdc7fced2f658eef987c9_r.jpg&cdnurl=https%3a%2f%2fth.bing.com%2fth%2fid%2fR.286ba019ab88ca85a9f0151ab1e5e8ff%3frik%3dryhmeZ%252fgnGxR9g%26pid%3dImgRaw%26r%3d0&exph=466&expw=706&q=%e8%94%a1%e5%be%90%e5%9d%a4%e6%a2%97%e5%9b%be&simid=608026898962196410&FORM=IRPRST&ck=E45372B2C397EE10BF2519E586F6D747&selectedIndex=0&itb=0', '坤坤.jfif')
